package TSP;

import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


public class RawDataHandler 
{
	public static TSPMap ParseData(String file) throws IOException
	{
		BufferedReader br = new BufferedReader(new FileReader(file));
		TSPMap map = new TSPMap();
	    try 
	    {	        
	        String line = br.readLine();
	        String[] s = line.split(" ");
	        int nbCity = Integer.parseInt(s[0]);
	        map.Initialize(nbCity);
	        int cityId = 0;

	        
	        String[] curLine;
	        line = br.readLine();
	        
	        int temp = 0;
	        
	        while (line != null) 
	        {	            
	            curLine = line.split(" ");
	            map.AddCity(cityId++, Float.parseFloat(curLine[0]), Float.parseFloat(curLine[1]));
	            
	            line = br.readLine();
	        }

	    } 
	    finally 
	    {
	        br.close();
	    }
	    
	    return map;
	}
	
	public static void OutputSolution(TSPMap map)
	{
		int startingCity = 0;
		int nextCity = map.cityList[startingCity].getNextDestination().originalId;
		String path = "";
		double distanceTotal = map.cityList[startingCity].distance[nextCity];
		path += map.cityList[startingCity].originalId + " ";
		City nextCityObj = map.cityList[nextCity];
		
		while(nextCity != startingCity)
		{
			path += map.cityList[nextCity].originalId + " ";
			int curCity = nextCity;
			nextCityObj = map.cityList[nextCity].getNextDestination();
			if (nextCityObj == null)
			{
				nextCityObj = map.cityList[startingCity];
			}
			nextCity = nextCityObj.originalId;
			distanceTotal += map.cityList[curCity].distance[nextCity];
		}
		
		System.out.println(distanceTotal + " 0");
		System.out.println(path);
	}
}
